CC=g++
#wildcard, this finds all *.c file and make *.o files
objects = $(patsubst %.c,%.o,$(wildcard *.c))

#include $(shell root-config --prefix)/etc/Makefile.arch

# make sure root-config is defined
DELPHES_DIR := /home/timlou/research/software/Delphes-3.0.12

ROOTFLAGS := `root-config --cflags`
ROOTLIBS := -L`root-config --libdir` -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic

#include delphes exroot
INC := -I$(DELPHES_DIR) -I$(DELPHES_DIR)/classes -I$(DELPHES_DIR)/external/ExRootAnalysis 
LIB := -L$(DELPHES_DIR) -lDelphes -Wl,-rpath $(DELPHES_DIR)

all: Analysis_OutputTree Analysis_Muons Fisher

#rule for basic objects
%.o: %.c %.h
	$(CXX) -Wall -g -c $< \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o $@

#analysis code
Analysis: $(objects) Analysis.C
	$(CXX) -g $(objects) CmdLine/CmdLine.o Analysis.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o Analysis.exe

Analysis_Delphes_muoneff: $(objects) Analysis_Delphes_muoneff.C
	$(CXX) -g $(objects) CmdLine/CmdLine.o Analysis_Delphes_muoneff.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o Analysis_Delphes_muoneff.exe


#code to combine covariance matrix for fisher discriminant
Fisher: $(objects) Fisher.C
	$(CXX) -g $(objects) CmdLine/CmdLine.o Fisher.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o Fisher.exe

histmaker: histmaker.C
	$(CXX) -g CmdLine/CmdLine.o histmaker.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o histmaker.exe

histmaker_2: histmaker_2.C
	$(CXX) -g CmdLine/CmdLine.o histmaker_2.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o histmaker_2.exe

histmaker_3: histmaker_3.C
	$(CXX) -g CmdLine/CmdLine.o histmaker_3.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o histmaker_3.exe

combine_exc: combine_exc.C
	$(CXX) -g CmdLine/CmdLine.o combine_exc.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o combine_exc.exe

combine_dis: combine_dis.C
	$(CXX) -g CmdLine/CmdLine.o combine_dis.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o combine_dis.exe

#analysis code
Analysis_OutputTree: $(objects) Analysis_OutputTree.C
	$(CXX) -g $(objects) CmdLine/CmdLine.o Analysis_OutputTree.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o Analysis_OutputTree.exe

#analysis code for muons
Analysis_Muons: $(objects) Analysis_Muons.C
	$(CXX) -g $(objects) CmdLine/CmdLine.o Analysis_Muons.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o Analysis_Muons.exe

Exclusion: $(objects) Exclusion.C
	$(CXX) -g $(objects) CmdLine/CmdLine.o Exclusion.C \
	$(ROOTFLAGS) $(INC) \
	$(ROOTLIBS) $(LIB) \
	-o Exclusion.exe

#runCEws: runCEws.C
#	@echo "Compiling $^"
#	$(CXX) -g $(ROOTFLAGS) -I scripts -o bin/$@ $^ $(ROOTLIBS) -lRooStats -lRooFitCore
#-lHistFactory

runCEws: runCEws.C
	@echo "Compiling $^"
	$(CXX) $(ROOTFLAGS) -I scripts -o bin/$@ $^ $(ROOTLIBS) -lRooStats -lRooFitCore -lHistFactory
